﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace TriangleGame
{
    public partial class ImpostazioniPartita : PhoneApplicationPage
    {
        public ImpostazioniPartita()
        {
            InitializeComponent();
        }

        private void g1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            g1.Text = "";
        }

        private void g2_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            g2.Text = "";
        }

        private void righe_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            righe.Text = "";
        }

        private void colonne_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            colonne.Text = "";
        }

        private void righe_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (righe.Text.Length == 1)
            {
                int x = Int32.Parse(righe.Text);
                if (x <= 1 || x > 7)
                {
                    righe.Text = "";
                    MessageBox.Show("Insert a value between 2 and 7");
                }
            }
        }

        private void colonne_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (colonne.Text.Length == 1)
            {
                int x = Int32.Parse(colonne.Text);
                if (x <= 1 || x > 7)
                {
                    colonne.Text = "";
                    MessageBox.Show("Insert a value between 2 and 7");
                }
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e) //invio i dati allo stato dell'app per prenderli dall'altra parte
        {
            if ((g1.Text == "") || (g2.Text == "") || (righe.Text == "") || (colonne.Text == ""))
            {
                MessageBox.Show("Fill in all fields");
            }
            else
            {
                string nomeg1 = g1.Text;
                string nomeg2 = g2.Text;
                int numrighe = Convert.ToInt16(righe.Text);
                int numcolonne = Convert.ToInt16(colonne.Text);
                PhoneApplicationService.Current.State["nomeg1"] = nomeg1;
                PhoneApplicationService.Current.State["nomeg2"] = nomeg2;
                PhoneApplicationService.Current.State["numrighe"] = numrighe;
                PhoneApplicationService.Current.State["numcolonne"] = numcolonne;

                NavigationService.Navigate(new Uri("/Partita.xaml", UriKind.Relative));
            }
        }
    }
}